<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        .wp {
            width: 310px;
            height: 500px;
            margin: 0 auto;
        }
        
        input {
            width: 50px;
        }
    </style>
</head>

<body>
    <div class="wp">
        <input type="text" name="hour"> <label for="">时</label>
        <input type="text" name="minute"> <label for="">分</label>
        <input type="text" name="seconds"> <label for="">秒</label>
        <button>倒计时开始</button>
        <h1 align="center">
            </h>
    </div>
    <script>
        let hour = document.querySelector("[name=hour]");
        let minute = document.querySelector("[name=minute]");
        let seconds = document.querySelector("[name=seconds]");
        let btn = document.querySelector("button");
        let h1 = document.querySelector("h1");

        btn.onclick = function() {

            let hourVal = num(parseInt(hour.value))
            console.log(hourVal)
            let mintueVal = num(parseInt(hour.value))
            let secondsVal = num(parseInt(hour.value))
            let times = hourVal * 3600 + mintueVal * 60 + secondsVal;

            setInterval(function() {
                if (isNaN(times)) {
                    return;
                }
                --times;
                if (times < 0) {
                    h1.innerHTML = "时间到"
                    return;
                }
                let h = parseInt(times / 3600);
                let m = parseInt(times % 3600 / 60);
                let s = parseInt(times % 60);
                h1.innerHTML = `${fill0(h)}:${fill0(m)}:${fill0(s)}`
            }, 1000)
        }

        function fill0(num) {
            return num < 10 ? "0" + num : num;
        }

        function num(str) {
            if (isNaN(str) && str !== "") {
                h1.innerHTML = "请输入合法数字";
                return NaN;
            }
            return str
        }
    </script>
</body>

</html>